package main

func candy(ratings []int) int {
	left := make([]int, len(ratings))
	for i := range ratings {
		if i == 0 {
			left[i] = 1
		} else if ratings[i] > ratings[i-1] {
			left[i] = left[i-1] + 1
		} else {
			left[i] = 1
		}
	}
	right := make([]int, len(ratings))
	for i := len(ratings) - 1; i >= 0; i-- {
		if i == len(ratings) - 1 {
			right[i] = 1
		} else if ratings[i] > ratings[i+1] {
			right[i] = right[i+1] + 1
		} else {
			right[i] = 1
		}
	}
	sum := 0
	for i := range ratings {
		if left[i] > right[i] {
			sum += left[i]
		} else {
			sum += right[i]
		}
	}
	return sum
}

func main() {
	res := candy([]int{1, 0, 2})
	println(res)
}